package algorithm.linear;

/**
 * 链式栈
 * @param <E>
 */
public class LinkedStack<E> implements SStack {
    private Node<E> top;//栈顶结点

    public LinkedStack() {
        this.top = null;
    }

    public boolean isEmpty() {
        return this.top == null;
    }

    public boolean push(Object element) {
        if (element == null)
            return false;
        this.top = new Node(element,this.top);
        return true;
    }

    public E pop() {
        if (!isEmpty()){
            E temp = this.top.data;
            this.top = this.top.next;
            return temp;
        }
        return null;
    }

    public Object get() {
        if (!isEmpty()){
            return this.top.data;
        }
        return null;
    }

}
